import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/**
 * 懒加载
 * view 嵌套路由 最顶层的出口
 * Home 首页
 * classifyIndex 分类页
 * classifyResult 自营专区
 * todayIndex 今日推荐
 * searchIndex 搜索页
 * Login 登录页
 * LoginMobile 验证码登录
 * ProductDetail  商品详情
 * CartIndex 购物车
 */

const View = resolve => require(['../page/View'], resolve)
const Home = resolve => require(['../page/Home'], resolve)
const ClassifyIndex = resolve => require(['../page/classify/Index'], resolve)
const ClassifyResult = resolve => require(['../page/classify/Result'], resolve)
const TodayIndex = resolve => require(['../page/index/Today'], resolve)
const SearchIndex = resolve => require(['../page/index/Search'], resolve)
const Login = resolve => require(['../page/index/Login'], resolve)
const LoginMobile = resolve => require(['../page/index/Mobile'], resolve)
const IntegralIndex = resolve => require(['../page/integral/Index'], resolve)
const ProductDetail = resolve => require(['../page/product/Detail'], resolve)
const CartIndex = resolve => require(['../page/cart/Index'], resolve)

// 路由配置
const routes = [{
    path: '/',
    component: Home
}, {
    path: '/classify',
    component: View,
    children: [{
        path: '',
        redirect: '/'
    }, {
        path: 'index',
        component: ClassifyIndex,
    }, {
        path: 'result',
        component: ClassifyResult
    }]
}, {
    path: '/index',
    component: View,
    children: [{
        path: '',
        redirect: '/'
    }, {
        path: 'today',
        component: TodayIndex
    }, {
        path: 'search',
        component: SearchIndex
    }, {
        path: 'login',
        component: Login
    }, {
        path: 'mobile',
        component: LoginMobile
    }]
}, {
    path: '/product/detail/',
    component: ProductDetail
}, {
    path: '/cart',
    component: CartIndex
}, {
    path: '/integral',
    component: View,
    children: [{
        path: '',
        redirect: '/'
    }, {
        path: 'index',
        component: IntegralIndex
    }]
}, {
    path: '*',
    redirect: '/'
}]

//创建 router 实例
const router = new Router({
    mode: 'history',
    routes
})

export default router